package com.kexio.core.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * Core Starter 配置属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.core")
public class CoreProperties {
    
    /**
     * 是否启用Core Starter
     */
    private boolean enabled = true;
    
    /**
     * 安全配置
     */
    private Security security = new Security();
    
    /**
     * Web配置
     */
    private Web web = new Web();
    
    /**
     * 数据配置
     */
    private Data data = new Data();
    
    // Getters and Setters
    public boolean isEnabled() {
        return enabled;
    }
    
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
    
    public Security getSecurity() {
        return security;
    }
    
    public void setSecurity(Security security) {
        this.security = security;
    }
    
    public Web getWeb() {
        return web;
    }
    
    public void setWeb(Web web) {
        this.web = web;
    }
    
    public Data getData() {
        return data;
    }
    
    public void setData(Data data) {
        this.data = data;
    }
    
    /**
     * 安全配置
     */
    public static class Security {
        
        /**
         * 是否启用安全功能
         */
        private boolean enabled = true;
        
        /**
         * JWT配置
         */
        private Jwt jwt = new Jwt();
        
        // Getters and Setters
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public Jwt getJwt() {
            return jwt;
        }
        
        public void setJwt(Jwt jwt) {
            this.jwt = jwt;
        }
        
        /**
         * JWT配置
         */
        public static class Jwt {
            
            /**
             * JWT密钥
             */
            private String secret = "kexio-default-secret-key-change-in-production";
            
            /**
             * 过期时间(秒) - 默认2小时
             */
            private int expire = 7200;
            
            /**
             * 刷新令牌过期时间(秒) - 默认7天
             */
            private int refreshExpire = 604800;
            
            /**
             * 发行者
             */
            private String issuer = "kexio";
            
            // Getters and Setters
            public String getSecret() {
                return secret;
            }
            
            public void setSecret(String secret) {
                this.secret = secret;
            }
            
            public int getExpire() {
                return expire;
            }
            
            public void setExpire(int expire) {
                this.expire = expire;
            }
            
            public int getRefreshExpire() {
                return refreshExpire;
            }
            
            public void setRefreshExpire(int refreshExpire) {
                this.refreshExpire = refreshExpire;
            }
            
            public String getIssuer() {
                return issuer;
            }
            
            public void setIssuer(String issuer) {
                this.issuer = issuer;
            }
        }
    }
    
    /**
     * Web配置
     */
    public static class Web {
        
        /**
         * 是否启用Web功能
         */
        private boolean enabled = true;
        
        /**
         * CORS配置
         */
        private Cors cors = new Cors();
        
        /**
         * Swagger配置
         */
        private Swagger swagger = new Swagger();
        
        // Getters and Setters
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public Cors getCors() {
            return cors;
        }
        
        public void setCors(Cors cors) {
            this.cors = cors;
        }
        
        public Swagger getSwagger() {
            return swagger;
        }
        
        public void setSwagger(Swagger swagger) {
            this.swagger = swagger;
        }
        
        /**
         * CORS配置
         */
        public static class Cors {
            
            /**
             * 是否启用CORS
             */
            private boolean enabled = true;
            
            /**
             * 允许的源
             */
            private String[] allowedOrigins = {"*"};
            
            /**
             * 允许的方法
             */
            private String[] allowedMethods = {"GET", "POST", "PUT", "DELETE", "OPTIONS"};
            
            /**
             * 允许的头
             */
            private String[] allowedHeaders = {"*"};
            
            /**
             * 是否允许凭证
             */
            private boolean allowCredentials = true;
            
            // Getters and Setters
            public boolean isEnabled() {
                return enabled;
            }
            
            public void setEnabled(boolean enabled) {
                this.enabled = enabled;
            }
            
            public String[] getAllowedOrigins() {
                return allowedOrigins;
            }
            
            public void setAllowedOrigins(String[] allowedOrigins) {
                this.allowedOrigins = allowedOrigins;
            }
            
            public String[] getAllowedMethods() {
                return allowedMethods;
            }
            
            public void setAllowedMethods(String[] allowedMethods) {
                this.allowedMethods = allowedMethods;
            }
            
            public String[] getAllowedHeaders() {
                return allowedHeaders;
            }
            
            public void setAllowedHeaders(String[] allowedHeaders) {
                this.allowedHeaders = allowedHeaders;
            }
            
            public boolean isAllowCredentials() {
                return allowCredentials;
            }
            
            public void setAllowCredentials(boolean allowCredentials) {
                this.allowCredentials = allowCredentials;
            }
        }
        
        /**
         * Swagger配置
         */
        public static class Swagger {
            
            /**
             * 是否启用Swagger
             */
            private boolean enabled = true;
            
            /**
             * 标题
             */
            private String title = "Kexio API";
            
            /**
             * 描述
             */
            private String description = "Kexio系统API文档";
            
            /**
             * 版本
             */
            private String version = "1.0.0";
            
            // Getters and Setters
            public boolean isEnabled() {
                return enabled;
            }
            
            public void setEnabled(boolean enabled) {
                this.enabled = enabled;
            }
            
            public String getTitle() {
                return title;
            }
            
            public void setTitle(String title) {
                this.title = title;
            }
            
            public String getDescription() {
                return description;
            }
            
            public void setDescription(String description) {
                this.description = description;
            }
            
            public String getVersion() {
                return version;
            }
            
            public void setVersion(String version) {
                this.version = version;
            }
        }
    }
    
    /**
     * 数据配置
     */
    public static class Data {
        
        /**
         * 是否启用数据功能
         */
        private boolean enabled = true;
        
        /**
         * Flyway配置
         */
        private Flyway flyway = new Flyway();
        
        /**
         * 缓存配置
         */
        private Cache cache = new Cache();
        
        // Getters and Setters
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public Flyway getFlyway() {
            return flyway;
        }
        
        public void setFlyway(Flyway flyway) {
            this.flyway = flyway;
        }
        
        public Cache getCache() {
            return cache;
        }
        
        public void setCache(Cache cache) {
            this.cache = cache;
        }
        
        /**
         * Flyway配置
         */
        public static class Flyway {
            
            /**
             * 是否启用Flyway
             */
            private boolean enabled = true;
            
            /**
             * 脚本位置
             */
            private String[] locations = {"classpath:db/migration"};
            
            // Getters and Setters
            public boolean isEnabled() {
                return enabled;
            }
            
            public void setEnabled(boolean enabled) {
                this.enabled = enabled;
            }
            
            public String[] getLocations() {
                return locations;
            }
            
            public void setLocations(String[] locations) {
                this.locations = locations;
            }
        }
        
        /**
         * 缓存配置
         */
        public static class Cache {
            
            /**
             * 缓存类型: spring, redis, caffeine, hybrid
             */
            private String type = "hybrid";
            
            /**
             * 默认TTL(秒)
             */
            private int ttl = 600;
            
            // Getters and Setters
            public String getType() {
                return type;
            }
            
            public void setType(String type) {
                this.type = type;
            }
            
            public int getTtl() {
                return ttl;
            }
            
            public void setTtl(int ttl) {
                this.ttl = ttl;
            }
        }
    }
}
